/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Clientes.java
 *
 * Created on 11/09/2011, 16:10:29
 */

package sisgraf.view;
import java.util.List;
import sisgraf.model.Cliente;
import sisgraf.controler.ClienteControler;


/**
 *
 * @author POSITIVO R41
 */
public class Clientes extends javax.swing.JDialog {
    private int opcao=0;
    private ClienteControler clienteControler;
    private Cliente cliente;
    private boolean incluiu=false;

    /** Creates new form Clientes */
    public Clientes(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }
    public void setOpcao(int opcao)
    {
        this.opcao = opcao;
        formComponentResized(null);
        setLocationRelativeTo(null);
        jTxFdCpfCnpj.setText(cliente.getCpf_cnpj());
        jTxFdNomCli.setText(cliente.getNom_cli());
        jTxFdEndLog.setText(cliente.getEnd_log());
        jTxFdEndCom.setText(cliente.getEnd_com());
        jTxFdEndBai.setText(cliente.getEnd_bai());
        jTxFdEndCid.setText(cliente.getEnd_cid());
        jTxFdEmail.setText(cliente.getEmail());
        jTxFdTelFix.setText(cliente.getTel_fix());
        jTxFdTelCel.setText(cliente.getTel_cel());
        jTxFdTelFax.setText(cliente.getTel_fax());
        jTxFdAniversario.setText(cliente.getAniversario());
        jCbBxUf.setSelectedIndex(-1);
        if (this.opcao == Menu.OP_PESQ_ALT){
            jTxFdCodigo.setText(cliente.getId().toString());
            if (cliente.getAtivo().equals("S"))
                jCkBxAtivo.setSelected(true);
            else
                jCkBxAtivo.setSelected(false);
            jTxFdEndNum.setText(cliente.getEnd_num()==null?"":cliente.getEnd_num().toString());
            jTxFdEndCep.setText(cliente.getEnd_cep()==null?"":cliente.getEnd_cep().toString());
            if (cliente.getEnd_uf()!=null){
                for (int i = 0; i<Menu.UF.length; i++){
                    if (cliente.getEnd_uf().equals(Menu.UF[i]))
                        jCbBxUf.setSelectedIndex(i);
                }
            }
        } else {
            jTxFdCodigo.setText("");
            jTxFdEndNum.setText("");
            jTxFdEndCep.setText("");
            jCkBxAtivo.setSelected(false);
        }
        jTxFdCodigo.setEnabled(false);
        setVisible(true);
        jTxFdNomCli.setFocusable(true);
    }
    public void setCliente(Cliente cliente){
        this.cliente = cliente;
    }
    public void setControler(ClienteControler clienteControler){
        this.clienteControler = clienteControler;
    }
    public boolean getncluiu(){
        return this.incluiu;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPnlSuperior = new javax.swing.JPanel();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        jPnlCentral = new javax.swing.JPanel();
        jPnlConteudo = new javax.swing.JPanel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        jTxFdCodigo = new javax.swing.JTextField();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        jTxFdNomCli = new javax.swing.JTextField();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        jTxFdCpfCnpj = new javax.swing.JTextField();
        jCkBxAtivo = new javax.swing.JCheckBox();
        javax.swing.JPanel jPanel1 = new javax.swing.JPanel();
        javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        jTxFdEndLog = new javax.swing.JTextField();
        javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
        jTxFdEndNum = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
        jTxFdEndCom = new javax.swing.JTextField();
        javax.swing.JLabel jLabel12 = new javax.swing.JLabel();
        jTxFdEndBai = new javax.swing.JTextField();
        javax.swing.JLabel jLabel13 = new javax.swing.JLabel();
        jTxFdEndCep = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel14 = new javax.swing.JLabel();
        jTxFdEndCid = new javax.swing.JTextField();
        javax.swing.JLabel jLabel15 = new javax.swing.JLabel();
        jCbBxUf = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel16 = new javax.swing.JLabel();
        jTxFdEmail = new javax.swing.JTextField();
        javax.swing.JLabel jLabel17 = new javax.swing.JLabel();
        jTxFdTelFix = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel18 = new javax.swing.JLabel();
        jTxFdTelCel = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel20 = new javax.swing.JLabel();
        jTxFdAniversario = new javax.swing.JFormattedTextField();
        javax.swing.JLabel jLabel19 = new javax.swing.JLabel();
        jTxFdTelFax = new javax.swing.JFormattedTextField();
        jPnlControle = new javax.swing.JPanel();
        jBtFinalizar = new javax.swing.JButton();
        jBtConfirmar = new javax.swing.JButton();
        jPnlInferior = new javax.swing.JPanel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPnlSuperior.setBorder(new javax.swing.border.MatteBorder(null));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("SISTEMA DE ORÇAMENTOS PARA SERVIÇOS GRAFICOS");
        jLabel1.setMinimumSize(new java.awt.Dimension(0, 14));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Clientes");
        jLabel2.setMinimumSize(new java.awt.Dimension(0, 14));

        javax.swing.GroupLayout jPnlSuperiorLayout = new javax.swing.GroupLayout(jPnlSuperior);
        jPnlSuperior.setLayout(jPnlSuperiorLayout);
        jPnlSuperiorLayout.setHorizontalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 642, Short.MAX_VALUE)
        );
        jPnlSuperiorLayout.setVerticalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlSuperiorLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlCentral.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPnlCentral.setMinimumSize(new java.awt.Dimension(100, 0));

        jPnlConteudo.setBorder(javax.swing.BorderFactory.createLineBorder(null));

        jLabel5.setText("Código:");

        jLabel6.setText("Nome:");

        jLabel7.setText("CPF/CNPJ:");

        jCkBxAtivo.setText("Ativo");

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));

        jLabel8.setText("Endereço");

        jLabel9.setText("Logradouro:");

        jLabel10.setText("Número:");

        jTxFdEndNum.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,##0"))));

        jLabel11.setText("Complemento:");

        jLabel12.setText("Bairro");

        jLabel13.setText("CEP:");

        try {
            jTxFdEndCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jTxFdEndCep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxFdEndCepActionPerformed(evt);
            }
        });

        jLabel14.setText("Cidade:");

        jLabel15.setText("UF:");

        jCbBxUf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndLog, javax.swing.GroupLayout.DEFAULT_SIZE, 479, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndNum, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndCom, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndBai, javax.swing.GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTxFdEndCep, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel14)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdEndCid, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCbBxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jTxFdEndLog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(jTxFdEndNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTxFdEndCom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(jTxFdEndBai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTxFdEndCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(jTxFdEndCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCbBxUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel16.setText("e-mail:");

        jLabel17.setText("Tel.Fixo:");

        jLabel18.setText("Tel.Celular:");

        jLabel20.setText("Aniversario:");

        jTxFdAniversario.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM"))));

        jLabel19.setText("fAX");

        javax.swing.GroupLayout jPnlConteudoLayout = new javax.swing.GroupLayout(jPnlConteudo);
        jPnlConteudo.setLayout(jPnlConteudoLayout);
        jPnlConteudoLayout.setHorizontalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdNomCli, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTxFdCpfCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12)
                                .addComponent(jCkBxAtivo, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)))
                        .addGap(50, 50, 50))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(50, 50, 50))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 572, Short.MAX_VALUE))
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdTelFix, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel18)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel19)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdTelFax, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
                                .addGap(17, 17, 17)
                                .addComponent(jLabel20)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTxFdAniversario, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        jPnlConteudoLayout.setVerticalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTxFdCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTxFdNomCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jCkBxAtivo)
                    .addComponent(jTxFdCpfCnpj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel16)
                    .addComponent(jTxFdEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jTxFdTelFix, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTxFdAniversario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20)
                    .addComponent(jLabel18)
                    .addComponent(jTxFdTelCel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19)
                    .addComponent(jTxFdTelFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPnlControle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jBtFinalizar.setText("Finalizar");
        jBtFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtFinalizarActionPerformed(evt);
            }
        });

        jBtConfirmar.setText("Confirmar");
        jBtConfirmar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtConfirmarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlControleLayout = new javax.swing.GroupLayout(jPnlControle);
        jPnlControle.setLayout(jPnlControleLayout);
        jPnlControleLayout.setHorizontalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(450, Short.MAX_VALUE)
                .addComponent(jBtConfirmar)
                .addGap(18, 18, 18)
                .addComponent(jBtFinalizar)
                .addContainerGap())
        );
        jPnlControleLayout.setVerticalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addGroup(jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtFinalizar)
                    .addComponent(jBtConfirmar))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPnlCentralLayout = new javax.swing.GroupLayout(jPnlCentral);
        jPnlCentral.setLayout(jPnlCentralLayout);
        jPnlCentralLayout.setHorizontalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlCentralLayout.createSequentialGroup()
                .addGroup(jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPnlControle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPnlConteudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPnlCentralLayout.setVerticalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlCentralLayout.createSequentialGroup()
                .addComponent(jPnlConteudo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlControle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlInferior.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Gráfica Modêlo");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Grupo de Estudo PMA Anhanguera");

        javax.swing.GroupLayout jPnlInferiorLayout = new javax.swing.GroupLayout(jPnlInferior);
        jPnlInferior.setLayout(jPnlInferiorLayout);
        jPnlInferiorLayout.setHorizontalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlInferiorLayout.createSequentialGroup()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 324, Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPnlInferiorLayout.setVerticalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlSuperior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlInferior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlCentral, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPnlSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlCentral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        jPnlControle.setBorder(null);
        jPnlConteudo.setBorder(null);
        int dif = this.getHeight()-jPnlSuperior.getHeight()-jPnlCentral.getHeight()-jPnlInferior.getHeight()-6;
        jPnlCentral.setSize(this.getWidth(),this.getHeight()-jPnlSuperior.getHeight()-jPnlInferior.getHeight()-dif);
        jPnlConteudo.setSize(jPnlCentral.getWidth()-12,jPnlCentral.getHeight()-jPnlControle.getHeight());
        jPnlControle.setSize(jPnlCentral.getWidth()-12, jPnlControle.getHeight());
        jPnlControle.setLocation(2, jPnlConteudo.getHeight());
    }//GEN-LAST:event_formComponentResized

//GEN-FIRST:event_jTxFdEndCepActionPerformed
    private void jTxFdEndCepActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

//GEN-LAST:event_jTxFdEndCepActionPerformed

    private void jBtFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtFinalizarActionPerformed
        // TODO add your handling code here:
        String dbCpf_cnpj=cliente.getCpf_cnpj()==null?"":cliente.getCpf_cnpj();
        String dbNomVen=cliente.getNom_cli()==null?"":cliente.getNom_cli();
        String dbAtivo=cliente.getAtivo()==null?"":cliente.getAtivo();
        String dbEndLog=cliente.getEnd_log()==null?"":cliente.getEnd_log();
        String dbEndNum=cliente.getEnd_num()==null?"":cliente.getEnd_num().toString();
        String dbEndCom=cliente.getEnd_com()==null?"":cliente.getEnd_com();
        String dbEndBai=cliente.getEnd_bai()==null?"":cliente.getEnd_bai();
        String dbEndCep=cliente.getEnd_cep()==null?"":cliente.getEnd_cep().toString();
        String dbEndCid=cliente.getEnd_cid()==null?"":cliente.getEnd_cid();
        String dbEndUf=cliente.getEnd_uf()==null?"":cliente.getEnd_uf();
        String dbEmail=cliente.getEmail()==null?"":cliente.getEmail();
        String dbTelFix=cliente.getTel_fix()==null?"":cliente.getTel_fix();
        String dbTelCel=cliente.getTel_cel()==null?"":cliente.getTel_cel();
        String dbTelFax=cliente.getTel_fix()==null?"":cliente.getTel_fax();
        String dbAniversario=cliente.getAniversario()==null?"":cliente.getAniversario();
        String igAtivo=jCkBxAtivo.isEnabled()?"S":"N";
        String igEndCep=jTxFdEndCep.getText();
        igEndCep=igEndCep.substring(0,2)+igEndCep.substring(3,6)+igEndCep.substring(7,10);
        if (!jTxFdCpfCnpj.getText().equals(dbCpf_cnpj)||
                !jTxFdNomCli.getText().equals(dbNomVen)||
                !igAtivo.equals(dbAtivo)||
                !jTxFdEndLog.getText().equals(dbEndLog)||
                !jTxFdEndNum.getText().equals(dbEndNum)||
                !jTxFdEndCom.getText().equals(dbEndCom)||
                !jTxFdEndBai.getText().equals(dbEndBai)||
                !igEndCep.equals(dbEndCep)||
                !jTxFdEndCid.getText().equals(dbEndCid)||
                !jCbBxUf.getSelectedItem().equals(dbEndUf)||
                !jTxFdEmail.getText().equals(dbEmail)||
                !jTxFdTelFix.getText().equals(dbTelFix)||
                !jTxFdTelCel.getText().equals(dbTelCel)||
                !jTxFdTelFax.getText().equals(dbTelFax)||
                !jTxFdAniversario.getText().equals(dbAniversario)
                ){
            if (javax.swing.JOptionPane.showConfirmDialog(null,
                    "Modificações foram feitas, deseja realmente finalizar sem salvar ?",
                    "Finalizar", javax.swing.JOptionPane.YES_NO_OPTION)==0){
                Clientes.this.dispose();
            }
        } else Clientes.this.dispose();
}//GEN-LAST:event_jBtFinalizarActionPerformed

    private void jBtConfirmarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtConfirmarActionPerformed
        // TODO add your handling code here:
        boolean gravarOk = true;
        String mensErro="Dados não puderam ser salvos, apresentaram os seguintes erro:";
        String igUf= null;
        if (jCbBxUf.getSelectedIndex()<0){
            gravarOk=false;
            mensErro+="\nDeve ser selecionada ua unidade federativa no endereço";
        } else {
            igUf=jCbBxUf.getSelectedItem().toString();
        }
        if (jTxFdCpfCnpj==null||jTxFdCpfCnpj.getText().equals("")||!Menu.validaCpfCnpj(jTxFdCpfCnpj.getText())){
            gravarOk=false;
            mensErro+="\nNúmero do CNPJ ou CPF inválido";
        }
        String igEndCep=jTxFdEndCep.getText().replaceAll("\\.", "");
        igEndCep=igEndCep.replaceAll("-", "");
        String igEndNum=jTxFdEndNum.getText().replaceAll("\\.", "");
        if (jTxFdNomCli==null||jTxFdNomCli.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo nome deve ser preenchido";
        }
        if (jTxFdCpfCnpj==null||jTxFdCpfCnpj.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo CPF/CNPJ deve ser preenchido";
        }
        if (jTxFdEndLog==null||jTxFdEndLog.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo logradouro no endereço deve ser preenchido";
        }
        if (jTxFdEndCep==null||igEndCep.equals("")){
            gravarOk=false;
            mensErro+="\nO campo CEP no endereço deve ser preenchido";
        }
        if (jTxFdEndCid==null||jTxFdEndCid.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo cidade no endereço deve ser preenchido";
        }
        if (igUf==null||igUf.equals("")){
            gravarOk=false;
            mensErro+="\nO campo UF no endereço deve ser preenchido";
        }
        if (jTxFdEmail==null||jTxFdEmail.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo Email deve ser preenchido";
        }
        if (jTxFdTelCel==null||jTxFdTelCel.getText().equals("")){
            gravarOk=false;
            mensErro+="\nO campo Telefone Celular deve ser preenchido";
        }
        if (!Menu.validaDiaMes(jTxFdAniversario.getText())){
            gravarOk=false;
            mensErro+="\nAniversário invalido";
        }
        if (!gravarOk){
            javax.swing.JOptionPane.showMessageDialog(null,
                    mensErro+"\n"
                    + "Corrija as informações listadas e tente confirmar novamente ",
                    "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            cliente.setNom_cli(jTxFdNomCli.getText());
            cliente.setCpf_cnpj(jTxFdCpfCnpj.getText());
            cliente.setAtivo(jCkBxAtivo.isEnabled()?"S":"N");
            cliente.setEnd_log(jTxFdEndLog.getText());
            cliente.setEnd_num(Integer.parseInt(igEndNum));
            cliente.setEnd_com(jTxFdEndCom.getText());
            cliente.setEnd_bai(jTxFdEndBai.getText());
            cliente.setEnd_cep(Integer.parseInt(igEndCep));
            cliente.setEnd_cid(jTxFdEndCid.getText());
            cliente.setEnd_uf(jCbBxUf.getSelectedItem().toString());
            cliente.setEmail(jTxFdEmail.getText());
            cliente.setTel_fix(jTxFdTelFix.getText());
            cliente.setTel_cel(jTxFdTelCel.getText());
            cliente.setTel_fax(jTxFdTelFax.getText());
            cliente.setAniversario(jTxFdAniversario.getText());
            if (this.opcao == Menu.OP_PESQ_ALT){
                if (!clienteControler.alterarCliente(cliente)){
                    javax.swing.JOptionPane.showMessageDialog(null,
                            "Erro na atualização dos dados do cliente",
                            "Acesso ao Banco de Dados",
                            javax.swing.JOptionPane.INFORMATION_MESSAGE);
                }
            } else if (this.opcao == Menu.OP_PESQ_INC){
                boolean teste=clienteControler.adicionarCliente(cliente);
                if (!teste){
                    javax.swing.JOptionPane.showMessageDialog(null,
                            "Erro na inclusão do cliente",
                            "Acesso ao Banco de Dados",
                            javax.swing.JOptionPane.INFORMATION_MESSAGE);
                } this.incluiu = true;
            }
            Clientes.this.dispose();
        }
}//GEN-LAST:event_jBtConfirmarActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        // TODO add your handling code here:
        clienteControler.liberarCliente();

    }//GEN-LAST:event_formWindowClosed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Clientes dialog = new Clientes(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtConfirmar;
    private javax.swing.JButton jBtFinalizar;
    private javax.swing.JComboBox jCbBxUf;
    private javax.swing.JCheckBox jCkBxAtivo;
    private javax.swing.JPanel jPnlCentral;
    private javax.swing.JPanel jPnlConteudo;
    private javax.swing.JPanel jPnlControle;
    private javax.swing.JPanel jPnlInferior;
    private javax.swing.JPanel jPnlSuperior;
    private javax.swing.JFormattedTextField jTxFdAniversario;
    private javax.swing.JTextField jTxFdCodigo;
    private javax.swing.JTextField jTxFdCpfCnpj;
    private javax.swing.JTextField jTxFdEmail;
    private javax.swing.JTextField jTxFdEndBai;
    private javax.swing.JFormattedTextField jTxFdEndCep;
    private javax.swing.JTextField jTxFdEndCid;
    private javax.swing.JTextField jTxFdEndCom;
    private javax.swing.JTextField jTxFdEndLog;
    private javax.swing.JFormattedTextField jTxFdEndNum;
    private javax.swing.JTextField jTxFdNomCli;
    private javax.swing.JFormattedTextField jTxFdTelCel;
    private javax.swing.JFormattedTextField jTxFdTelFax;
    private javax.swing.JFormattedTextField jTxFdTelFix;
    // End of variables declaration//GEN-END:variables

}
